package client.networking;
import java.awt.EventQueue;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import server.networking.GameplayRemoteInterface;
import server.networking.PolicyGetter;
import server.networking.ServerRemoteInterface;
import controller.Controller;
import controller.LoginController;

/**
 * The Client class is the starting point of the Royally Flushed client.
 * It starts a thread in which it connects to the game server, then 
 * initialises the RMI stub.
 *
 */

public class Client {
	public static void main(String[] args) throws RemoteException, NotBoundException {
		final String HOST = "localhost";
		final int PORT = 1099;
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					System.setProperty("java.security.policy", PolicyGetter.getPolicyLocation("client"));
					if (System.getSecurityManager() == null) {
						System.setSecurityManager(new SecurityManager());
					}
					
					Registry reg = LocateRegistry.getRegistry(HOST, PORT);
					ServerRemoteInterface serverRemote = (ServerRemoteInterface) reg.lookup("Server");
					
					Controller controller = new LoginController();
					
					controller.setServerRemote(serverRemote);
					
				} catch (Exception e) {
					e.printStackTrace();				}
			}
		});
		
	}

}
